<template>
  <div class="up-info">
    <div class="up-avatar-wrapper">
      <img v-img-error :src="upInfo.avatar" alt="UP主头像" class="up-avatar">
      <div v-if="upInfo.level" class="up-level-badge">{{ upInfo.level }}</div>
    </div>
    <div class="up-details">
      <div class="up-name-row">
        <span class="up-name">{{ upInfo.name }}</span>
        <div class="up-badges">
          <span v-if="upInfo.isOfficial" class="official-badge">官方认证</span>
          <span v-if="upInfo.isCreator" class="creator-badge">创作者</span>
        </div>
      </div>
      <div class="up-stats">
        <span class="up-followers">粉丝：{{ formatNumber(upInfo.followers) }}</span>
        <span v-if="upInfo.videosCount" class="up-videos">视频：{{ formatNumber(upInfo.videosCount) }}</span>
      </div>
    </div>
    <div class="up-actions">
      <button 
        class="follow-btn" 
        :class="{ 'following': isFollowing }" 
        :disabled="isProcessing"
        @click="toggleFollow"
      >
        <span v-if="isProcessing">处理中...</span>
        <span v-else-if="isFollowing">已关注</span>
        <span v-else>关注</span>
      </button>
      <button 
        v-if="allowMessage" 
        class="message-btn"
        @click="sendMessage"
      >
        私信
      </button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'UpInfo',
  props: {
    upInfo: {
      type: Object,
      required: true,
      default: () => ({
        name: '',
        avatar: '',
        followers: 0,
        level: 0,
        isOfficial: false,
        isCreator: false,
        videosCount: 0,
      }),
    },
    isFollowing: {
      type: Boolean,
      default: false,
    },
    isProcessing: {
      type: Boolean,
      default: false,
    },
    allowMessage: {
      type: Boolean,
      default: true,
    },
  },
  methods: {
    formatNumber(num) {
      if (num >= 10000) {
        return (num / 10000).toFixed(1) + '万'
      }
      return num.toString()
    },
    toggleFollow() {
      if (!this.isProcessing) {
        this.$emit('toggle-follow')
      }
    },
    sendMessage() {
      this.$emit('send-message', this.upInfo.name)
    },
  },
}
</script>

<style scoped>
.up-info {
  display: flex;
  align-items: center;
  padding: 15px 0;
}

.up-avatar-wrapper {
  position: relative;
  margin-right: 15px;
}

.up-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 1px solid #e5e5e5;
}

.up-level-badge {
  position: absolute;
  bottom: 0;
  right: 0;
  background-color: var(--bilibili-pink, #FB7299);
  color: white;
  font-size: 12px;
  font-weight: bold;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
}

.up-details {
  flex: 1;
}

.up-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.up-name {
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.up-badges {
  display: flex;
  gap: 6px;
}

.official-badge,
.creator-badge {
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 3px;
}

.official-badge {
  background-color: #00a1d6;
  color: white;
}

.creator-badge {
  background-color: #fb7299;
  color: white;
}

.up-stats {
  display: flex;
  gap: 15px;
  font-size: 14px;
  color: #999;
}

.up-actions {
  display: flex;
  gap: 10px;
}

.follow-btn,
.message-btn {
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.follow-btn {
  background-color: var(--bilibili-pink, #FB7299);
  color: white;
  border: 1px solid var(--bilibili-pink, #FB7299);
}

.follow-btn:hover:not(:disabled) {
  background-color: #ff5777;
  transform: translateY(-1px);
}

.follow-btn.following {
  background-color: #fff;
  color: #666;
  border: 1px solid #e5e5e5;
}

.follow-btn.following:hover:not(:disabled) {
  background-color: #f5f5f5;
  color: #333;
}

.follow-btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

.message-btn {
  background-color: #fff;
  color: #666;
  border: 1px solid #e5e5e5;
}

.message-btn:hover {
  background-color: #f5f5f5;
  color: #333;
  transform: translateY(-1px);
}

/* 响应式调整 */
@media (max-width: 768px) {
  .up-info {
    padding: 12px 0;
  }
  
  .up-avatar {
    width: 50px;
    height: 50px;
  }
  
  .up-level-badge {
    width: 18px;
    height: 18px;
    font-size: 11px;
  }
  
  .up-name {
    font-size: 15px;
  }
  
  .follow-btn,
  .message-btn {
    padding: 6px 12px;
    font-size: 13px;
  }
  
  .up-stats {
    font-size: 13px;
    gap: 10px;
  }
}

@media (max-width: 480px) {
  .up-actions {
    flex-direction: column;
    gap: 6px;
  }
  
  .follow-btn,
  .message-btn {
    width: 80px;
    text-align: center;
  }
}
</style>